import { Injectable } from '@nestjs/common';
import fg from 'fast-glob';
import java from 'java';
import path from 'path';

@Injectable()
export class JvmService {
  private readonly jvm: any;
  constructor() {
    fg.globSync('java/lib/*.jar', {
      cwd: process.cwd(),
      absolute: true,
      objectMode: true,
      unique: true,
    }).forEach((file) => {
      console.log('加载jar包:', file.name);
      java.classpath.push(file.path);
    });
    java.classpath.push(path.join(process.cwd(), 'java/bin'));
    this.jvm = java;
  }

  get JVM() {
    return this.jvm;
  }

  import(path: string) {
    return this.jvm.import(path);
  }
}
